<%@ page import="swe.article.*"%>

<jsp:include page="layout/header.jsp" />
<% 
	Article article = (Article) request.getAttribute("article");
%>

<script src='http://jquery-star-rating-plugin.googlecode.com/svn/trunk/jquery.js' type="text/javascript"></script>
<script src='http://jquery-star-rating-plugin.googlecode.com/svn/trunk/jquery.MetaData.js' type="text/javascript" language="javascript"></script>
<script src='http://jquery-star-rating-plugin.googlecode.com/svn/trunk/jquery.rating.js' type="text/javascript" language="javascript"></script>
<link href='http://jquery-star-rating-plugin.googlecode.com/svn/trunk/jquery.rating.css' type="text/css" rel="stylesheet"/>


<div class="row-fluid">
	<div class="span12">
		<h2><a href="Article?action=view&id=<%= article.getID() %>"><%= article.getTitle() %></a>
			<small><%= article.getCategory().getName() %></small>
		</h2>
	</div>
</div>
<div class="row-fluid">
	<div class="span3">
		<img class="thumbnail" src="<%= article.getImage() %>" alt="">
	</div>
	<div class="span6 offset1">

		<h3>Beschreibung</h3>
		<p><%= article.getDescription() %></p>
	</div>

	<div class="span3">
	
	</div>
</div>


<div class="row-fluid">
	<div class="span3">
	<h3>Details</h3>
		<table class="table table-striped">
			<tbody>
				<tr>
					<td><strong>Ersteller</strong></td>
					<td><%= article.getUser().getUserName() %></td>
				</tr>
				<tr>
					<td><strong>Bewertung</strong></td>
					<td> 
					
						
						<%
						
						ArticleManager am = (ArticleManager) getServletContext().getAttribute("aManager");
						Double tmpAvgRating = am.getAverageRating(article.getUser());
						if (tmpAvgRating==0.0) {
							out.println("noch keine");
						} else {
							out.println(tmpAvgRating);
						}
						%>
						
						
						
					</td>
				</tr>
				<tr>
					<td><strong>Startpreis</strong></td>
					<td><%= article.getStartprice() %> &euro;</td>
				</tr>
				<tr>
					<td><strong>Ende</strong></td>
					<td><%= article.getEndDatetimeHuman() %></td>
				</tr>

			</tbody>
		</table>
			
	</div>
	<div class="span6 offset1">

<% 
		if(article.getIsAuction() == true) { %>
			<h3>Gebot erstellen</h3>
			
			<div class="input-append">
				<form method="post" action="Article?action=addBid">
					<input type="hidden" name="id" value="<%= article.getID() %>" /> 
					<input class="span5" id="appendedInputButton" name="bidValue" type="number" value="<%= article.getHighestBid()+1 %>">
					<input type="submit" class="btn btn-primary" value="Bieten" />
				</form>
			</div>
			
			
			<% if(!request.getAttribute("errorMessage").equals("")) { %>
				<div class="alert alert-error"><strong>Achtung!</strong> <%= request.getAttribute("errorMessage") %></div>
			<%}%>
			
			<% if (article.getBids().size() == 0) {%>
			
			<p><i>Noch keine Gebote vorhanden</i></p>
			
			<% } else { %>
			<table class="table table-striped">
				<thead>
					<tr><th>Gebot</th><th>Datum</th><th>User</th></tr>
				</thead>
				<tbody>
				<% for(int i = article.getBids().size(); i>0; i--) { %>
					<tr>
						<td><%= article.getBids().get(i-1).getBidValue() %> &euro;</td>
						<td><%= article.getBids().get(i-1).getCreatedHuman() %></td>
						<td><%= article.getBids().get(i-1).getUser().getUserName() %></td>
					</tr>
				<% } %>
				</tbody>
			</table>	
			<% } %>
	
		</div>
	
	
	</div>
	<% } else { %>
	
	

			
			
			
			
			<% if (article.isActive()) {%>
			
			<div class="input-append">
				<form method="post" action="Article?action=buy">
					<input type="hidden" name="article" value="<%= article.getID() %>" /> 
					
					<input type="submit" class="btn btn-primary" value="Sofort-Kaufen" />
				</form>
			</div>
			
			<!--  <p><i>Der Artikel kann noch gekauft werden</i></p>  -->
			
			<% } else if(article.getBids().size()>0){ %>
			<table class="table table-striped">
				<thead>
					<tr><th>Kaufpreis</th><th>Datum</th><th>User</th></tr>
				</thead>
				<tbody>
				<% for(int i = article.getBids().size(); i>0; i--) { %>
					<tr>
						<td><%= article.getBids().get(i-1).getBidValue() %> &euro;</td>
						<td><%= article.getBids().get(i-1).getCreatedHuman() %></td>
						<td><%= article.getBids().get(i-1).getUser().getUserName() %></td>
					</tr>
				<% } %>
				</tbody>
			</table>	
			<% } %>
			
			

	
		<% if(!request.getAttribute("errorMessage").equals("")) { %>
				<div class="alert alert-error"><strong>Achtung!</strong> <%= request.getAttribute("errorMessage") %></div>
			<%}%>
			
			
	
	
			<!--  	<button class="btn btn-primary btn-large">Artikel Sofort-Kaufen</button> -->
	
	<% }
%>

<jsp:include page="layout/footer.jsp" />
